package com.lz.d;

import java.util.Arrays;
import java.util.Random;

/**
 * @ClassName Demo33
 * @Description 随机数组的归并问题
 * @Author 2214361854
 * @Date 2022/5/27 16:27
 * @Version 1.0
 */
public class Demo33 {
    /**
     * 生成两个任意的随机数组，并将这两个数组按照数字大小按顺序归并到一个新数组中
     */
    public static void main(String[] args) {
        int[] arr1 = suiJi(10);
        int[] arr2 = suiJi(10);
        //顺序排序
        Arrays.sort(arr1);
        Arrays.sort(arr2);
        System.out.println(Arrays.toString(arr1));
        System.out.println(Arrays.toString(arr2));
        int[] arr3 = heBing(arr1,arr2);
        Arrays.sort(arr3);
        System.out.println(Arrays.toString(arr3));
    }

    private static int[] heBing(int[] a, int[] b) {
        int[] result = new int[a.length+b.length];
        System.arraycopy(a,0,result,0,a.length);
        System.arraycopy(b,0,result,a.length,b.length);
        return result;
    }

    /**
     * 生成数组
     * @param n
     * @return
     */
    private static int[] suiJi(int n) {
        int[] arr = new int[n];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = new Random().nextInt(100);
        }
        return arr;
    }
}
